package com.gongj.shej.demo;

/**
 * @program: shej
 * @description: 工厂模式
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-22 14:32
 **/
public interface FoodFactory {
    public IProduct2 createProduct();
    
    public static void main(String[] args) {
        FoodFactory pizza2Factory = new Pizza2Factory();
        FoodFactory hamburger2Factory = new Hamburger2Factory();
        pizza2Factory.createProduct().makeFood();
        hamburger2Factory.createProduct().makeFood();
    }
}

   
interface IProduct2 {
    /**
     * 产品的抽象方法，由具体的产品类去实现
     */
    public void makeFood();
}

class Pizza2 implements IProduct2{
    @Override
    public void makeFood() {
        System.out.println("制作具体产品-披萨");
    }
}


/**
 * @program: shej
 * @description: 具体产品-汉堡
 * @author: gongj
 * @Description: TODO
 * @create: 2020-07-22 14:16
 **/
class Hamburger2 implements IProduct2 {
    @Override
    public void makeFood() {
        System.out.println("制作具体产品-汉堡");
    }
}
/**
 * 生产汉堡的工厂
 */
class Hamburger2Factory implements FoodFactory{

    @Override
    public IProduct2 createProduct() {
        return new Hamburger2();
    }
}

/**
 * 生产披萨的工厂
 */
class Pizza2Factory implements FoodFactory{

    @Override
    public IProduct2 createProduct() {
        return new Pizza2();
    }
}